package com.ddxz.demo.clickhouse.controller;

import com.ddxz.demo.clickhouse.entity.ClickHouseEntity;
import com.ddxz.demo.clickhouse.service.ClickHouseService;
import com.ddxz.tool.web.annotation.DdxzRequestParam;
import com.ddxz.tool.web.dto.DdxzResponse;
import com.ddxz.tool.web.dto.PageRequest;
import io.swagger.annotations.Api;
import org.springframework.web.bind.annotation.*;

/**
 * description
 *
 * @author 朱宗刚
 * @version 1.0.0
 * @date 2021/3/22
 */

@RestController
@Api
public class ClickHouseController {
    @GetMapping(value = "/search")
    public DdxzResponse getPageList(@DdxzRequestParam PageRequest request) {
        return service.getPageList(request);
    }

    @PostMapping("/addDataTest")
    public DdxzResponse addDatatest(@RequestParam(name = "startDate") Long startDate) {
        return service.addDataTest(startDate);
    }

    @PostMapping("/update")
    public DdxzResponse update(@RequestBody ClickHouseEntity entity) {
        return service.update(entity);
    }

    @GetMapping("/generate/{tableName}")
    public DdxzResponse generateData(@PathVariable("tableName") String tableName, @RequestParam("start") String startDate, @RequestParam("stop") String stopDate) {
        return service.generateDate(tableName, startDate, stopDate);
    }

    private final ClickHouseService service;

    public ClickHouseController(ClickHouseService service) {
        this.service = service;
    }
}
